package com.javatest.springboot2basictest.aop;

import java.util.Objects;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author liuziyang
 * @create 2020-06-29 20:35
 */
@Component
@org.aspectj.lang.annotation.Aspect
public class Aspect {

    private final static Logger LOGGER = LoggerFactory.getLogger(Aspect.class);

    @Pointcut("execution(* com.javatest.springboot2basictest.service.*.*(..))")
    public void pointCut() {
    }

    @Around("pointCut()")
    public Object doAround(ProceedingJoinPoint joinPoint) {
        LOGGER.warn("enter aop");
        try {
            final Object proceed = joinPoint.proceed();
            if (Objects.isNull(proceed)) {
                System.out.println("return is void");
            }

            return proceed;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }

        return null;
    }
}
